// pages/facilityInformation/facilityInformation.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
var pebtnCry = app.globalData._network_path + 'pebtnCry.png';
var pebtnBlue = app.globalData._network_path + 'pebtnBlue.png';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pebtnCry: pebtnCry,
    pebtnBlue: pebtnBlue,
    shose:1,
    parts_id:"",
    equipment_id:"",
    id:"",
    info:{},
    index:0,
    top: app.globalData._network_path + 'flow1.png',
    mid: app.globalData._network_path + 'flow2.png',
    bot: app.globalData._network_path + 'flow3.png',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this; 
    var parts_id = options.parts_id;
    var equipment_id = options.equipment_id;
    var id =options.id;
    var index =options.index;
    that.setData({
      parts_id: parts_id,
      equipment_id: equipment_id,
      id:id,
      shose:id,
      index: index
    })
    that.equipmentDetail();
    that.partDetail();
  },
  //配件详情
  partDetail(){
    var that = this;
    app.ajax({
      url:'User/Equipmentlists/getPartsDetail',
      data: {"parts_id":that.data.parts_id},
      success:function(res){
        if (res.data.code == 1000) {
          WxParse.wxParse('article', 'html', res.data.data.parts_describe, that, 5);
        }
      }
    })
  },
  //设备详情
  equipmentDetail: function () {
    var that = this;
    var equipment_id = that.data.equipment_id;
    app.ajax({
      url: "User/Equipmentlists/equipmentDetail",
      data: { "equipment_id": equipment_id },
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            info: res.data.data
          })
        }
      }
    })
  },

  //点击选择
  choose(e){
    var that=this;
    var typex=e.currentTarget.dataset.typex;
    var index = e.currentTarget.dataset.index;
    var parts_id = e.currentTarget.dataset.parts_id;
    that.setData({
      shose: typex,
      index:index,
      parts_id: parts_id
    })
    that.partDetail();
  },
  //提示换芯
  hintfun(e){
    var that = this;
    var equipment_id = that.data.equipment_id;
    app.ajax({
      url: 'User/Equipmentlists/changeCore',
      method: 'POST',
      data:{
        equipment_id: equipment_id
      },
      success: function(res){
        app.showToast(res.data.message);
      }
    })
  }

})